package com.wc.算法提高课.E第五章_数学知识.组合计数.有趣的数列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/7 20:28
 * @description https://www.acwing.com/problem/content/1318/
 */
public class Main {
    /**
     * 思路：卡特兰数<p>
     * 卡特兰数定义<p>
     * 可以观察出从 1 ~ 2n,顺序选数, 选择奇数的个数要 >= 偶数的个数,将奇数看做1, 偶数看做0, 即是卡特兰数
     * C(2 * n, n) - C(2 * n, n - 1)
     *
     * @see com.wc.算法基础课.D第四讲数学知识.求组合数.满足条件的01序列
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2000010;
    static int[] primes = new int[N];
    static boolean[] st = new boolean[N];
    static int n, p, cnt = 0;

    public static void main(String[] args) {
        n = sc.nextInt();
        p = sc.nextInt();
        ola(2 * n);
        out.println((C(2 * n, n) - C(2 * n, n - 1) + p) % p);
        out.flush();
    }

    static long C(int n, int m) {
        long res = 1;
        for (int i = 0; i < cnt; i++) {
            int prime = primes[i];
            int s = get(n, prime) - get(m, prime) - get(n - m, prime);
            res = res * qmi(prime, s) % p;
        }
        return res;
    }

    static long qmi(long a, int k) {
        long res = 1;
        while (k > 0) {
            if ((k & 1) == 1) res = res * a % p;
            a = a * a % p;
            k >>= 1;
        }
        return res;
    }

    static int get(int n, int p) {
        int s = 0;
        while (n > 0) {
            s += n / p;
            n /= p;
        }
        return s;
    }

    static void ola(int n) {
        st[0] = st[1] = true;
        for (int i = 2; i <= n; i++) {
            if (!st[i]) primes[cnt++] = i;
            for (int j = 0; primes[j] <= n / i; j++) {
                st[i * primes[j]] = true;
                if (i % primes[j] == 0) break;
            }
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
